﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.IO;

namespace SimpleInfrastructure.Serialize
{
    public class NJsonSerializer :ISerializer
    {
        public dynamic Serialize(object o)
        {
            string json = JsonConvert.SerializeObject(o);
            return json;
        }

        public T Deserialize<T>(dynamic jsonStr)
        {
            T result = default(T);
            try
            {
                JsonSerializer serializer = new JsonSerializer();
                StringReader sr = new StringReader(jsonStr);
                result = (T)serializer.Deserialize(new JsonTextReader(sr), typeof(T));
            }
            catch (Exception ex)
            {
                
            }
            return result;
        }

        public T Deserialize<T>(dynamic o, T notuse)
        {
            return Deserialize<T>(o);
        }
    }
}
